import request from '@/common/request.js'
export function getUserLeaders(maxLevel, deptId, skipEmpty) {
	return request.request(
		`wflow/wflow/process/step/leader/level?maxLevel=${maxLevel}&deptId=${deptId}&skipEmpty=${skipEmpty}`,
		{
			data: { maxLevel: maxLevel, deptId: deptId, skipEmpty: skipEmpty },
		}
	)
}

export function getUserLeader(level, deptId, skipEmpty) {
	return request.request(
		`wflow/wflow/process/step/leader/level?level=${level}&deptId=${deptId}&skipEmpty=${skipEmpty}`,
		{
			data: { level: level, deptId: deptId, skipEmpty: skipEmpty },
		}
	)
}

export function getUsersByRoles(roles) {
	return request.request(`wflow/wflow/process/step/userByRoles`, {
		method: 'post',
		data: roles,
	})
}

function useRequest(userId, depts) {
	return request.request(
		`wflow/wflow/process/step/user/${userId}/belong/depts`,
		{
			method: 'post',
			data: depts,
		}
	)
}

export const userInDepts = async (userId, depts) => {
	let result = false
	result = await useRequest(userId, depts)
	return result
}

export default {
	getUserLeader,
	getUserLeaders,
	getUsersByRoles,
	userInDepts,
}
